<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Binding - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="Object.html">Object</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-eval">#eval</a>
    <li ><a href="#method-i-local_variable_defined-3F">#local_variable_defined?</a>
    <li ><a href="#method-i-local_variable_get">#local_variable_get</a>
    <li ><a href="#method-i-local_variable_set">#local_variable_set</a>
    <li ><a href="#method-i-local_variables">#local_variables</a>
    <li ><a href="#method-i-receiver">#receiver</a>
    <li ><a href="#method-i-source_location">#source_location</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Binding">
    <h1 id="class-Binding" class="class">
      class Binding
    </h1>

    <section class="description">
    
<p>Objects of class <a href="Binding.html"><code>Binding</code></a> encapsulate the execution context at some particular place in the code and retain this context for future use. The variables, methods, value of <code>self</code>, and possibly an iterator block that can be accessed in this context are all retained. <a href="Binding.html"><code>Binding</code></a> objects can be created using <a href="Kernel.html#method-i-binding"><code>Kernel#binding</code></a>, and are made available to the callback of <a href="Kernel.html#method-i-set_trace_func"><code>Kernel#set_trace_func</code></a> and instances of <a href="TracePoint.html"><code>TracePoint</code></a>.</p>

<p>These binding objects can be passed as the second argument of the <a href="Kernel.html#method-i-eval"><code>Kernel#eval</code></a> method, establishing an environment for the evaluation.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Demo</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">n</span>)
    <span class="ruby-ivar">@secret</span> = <span class="ruby-identifier">n</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_binding</span>
    <span class="ruby-identifier">binding</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">k1</span> = <span class="ruby-constant">Demo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">99</span>)
<span class="ruby-identifier">b1</span> = <span class="ruby-identifier">k1</span>.<span class="ruby-identifier">get_binding</span>
<span class="ruby-identifier">k2</span> = <span class="ruby-constant">Demo</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">-3</span>)
<span class="ruby-identifier">b2</span> = <span class="ruby-identifier">k2</span>.<span class="ruby-identifier">get_binding</span>

<span class="ruby-identifier">eval</span>(<span class="ruby-string">&quot;@secret&quot;</span>, <span class="ruby-identifier">b1</span>)   <span class="ruby-comment">#=&gt; 99</span>
<span class="ruby-identifier">eval</span>(<span class="ruby-string">&quot;@secret&quot;</span>, <span class="ruby-identifier">b2</span>)   <span class="ruby-comment">#=&gt; -3</span>
<span class="ruby-identifier">eval</span>(<span class="ruby-string">&quot;@secret&quot;</span>)       <span class="ruby-comment">#=&gt; nil</span>
</pre>

<p><a href="Binding.html"><code>Binding</code></a> objects have no class-specific methods.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-eval" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          eval(string [, filename [,lineno]])  &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Evaluates the Ruby expression(s) in <em>string</em>, in the <em>binding</em>’s context.  If the optional <em>filename</em> and <em>lineno</em> parameters are present, they will be used when reporting syntax errors.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_binding</span>(<span class="ruby-identifier">param</span>)
  <span class="ruby-identifier">binding</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">get_binding</span>(<span class="ruby-string">&quot;hello&quot;</span>)
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">eval</span>(<span class="ruby-string">&quot;param&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
</pre>

                              <div class="method-source-code" id="eval-source">
            <pre>static VALUE
bind_eval(int argc, VALUE *argv, VALUE bindval)
{
    VALUE args[4];

    rb_scan_args(argc, argv, &quot;12&quot;, &amp;args[0], &amp;args[2], &amp;args[3]);
    args[1] = bindval;
    return rb_f_eval(argc+1, args, Qnil /* self will be searched in eval */);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-local_variable_defined-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          local_variable_defined?(symbol) &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if a local variable <code>symbol</code> exists.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
  <span class="ruby-identifier">a</span> = <span class="ruby-value">1</span>
  <span class="ruby-identifier">binding</span>.<span class="ruby-identifier">local_variable_defined?</span>(<span class="ruby-value">:a</span>) <span class="ruby-comment">#=&gt; true</span>
  <span class="ruby-identifier">binding</span>.<span class="ruby-identifier">local_variable_defined?</span>(<span class="ruby-value">:b</span>) <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This method is the short version of the following code:</p>

<pre class="ruby"><span class="ruby-identifier">binding</span>.<span class="ruby-identifier">eval</span>(<span class="ruby-node">&quot;defined?(#{symbol}) == &#39;local-variable&#39;&quot;</span>)
</pre>

                              <div class="method-source-code" id="local_variable_defined-3F-source">
            <pre>static VALUE
bind_local_variable_defined_p(VALUE bindval, VALUE sym)
{
    ID lid = check_local_id(bindval, &amp;sym);
    const rb_binding_t *bind;
    const rb_env_t *env;

    if (!lid) return Qfalse;

    GetBindingPtr(bindval, bind);
    env = VM_ENV_ENVVAL_PTR(vm_block_ep(&amp;bind-&gt;block));
    return RBOOL(get_local_variable_ptr(&amp;env, lid));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-local_variable_get" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          local_variable_get(symbol) &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value of the local variable <code>symbol</code>.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
  <span class="ruby-identifier">a</span> = <span class="ruby-value">1</span>
  <span class="ruby-identifier">binding</span>.<span class="ruby-identifier">local_variable_get</span>(<span class="ruby-value">:a</span>) <span class="ruby-comment">#=&gt; 1</span>
  <span class="ruby-identifier">binding</span>.<span class="ruby-identifier">local_variable_get</span>(<span class="ruby-value">:b</span>) <span class="ruby-comment">#=&gt; NameError</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This method is the short version of the following code:</p>

<pre class="ruby"><span class="ruby-identifier">binding</span>.<span class="ruby-identifier">eval</span>(<span class="ruby-node">&quot;#{symbol}&quot;</span>)
</pre>

                              <div class="method-source-code" id="local_variable_get-source">
            <pre>static VALUE
bind_local_variable_get(VALUE bindval, VALUE sym)
{
    ID lid = check_local_id(bindval, &amp;sym);
    const rb_binding_t *bind;
    const VALUE *ptr;
    const rb_env_t *env;

    if (!lid) goto undefined;

    GetBindingPtr(bindval, bind);

    env = VM_ENV_ENVVAL_PTR(vm_block_ep(&amp;bind-&gt;block));
    if ((ptr = get_local_variable_ptr(&amp;env, lid)) != NULL) {
        return *ptr;
    }

    sym = ID2SYM(lid);
  undefined:
    rb_name_err_raise(&quot;local variable `%1$s&#39; is not defined for %2$s&quot;,
                      bindval, sym);
    UNREACHABLE_RETURN(Qundef);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-local_variable_set" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          local_variable_set(symbol, obj) &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Set local variable named <code>symbol</code> as <code>obj</code>.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
  <span class="ruby-identifier">a</span> = <span class="ruby-value">1</span>
  <span class="ruby-identifier">bind</span> = <span class="ruby-identifier">binding</span>
  <span class="ruby-identifier">bind</span>.<span class="ruby-identifier">local_variable_set</span>(<span class="ruby-value">:a</span>, <span class="ruby-value">2</span>) <span class="ruby-comment"># set existing local variable `a&#39;</span>
  <span class="ruby-identifier">bind</span>.<span class="ruby-identifier">local_variable_set</span>(<span class="ruby-value">:b</span>, <span class="ruby-value">3</span>) <span class="ruby-comment"># create new local variable `b&#39;</span>
                                 <span class="ruby-comment"># `b&#39; exists only in binding</span>

  <span class="ruby-identifier">p</span> <span class="ruby-identifier">bind</span>.<span class="ruby-identifier">local_variable_get</span>(<span class="ruby-value">:a</span>)  <span class="ruby-comment">#=&gt; 2</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">bind</span>.<span class="ruby-identifier">local_variable_get</span>(<span class="ruby-value">:b</span>)  <span class="ruby-comment">#=&gt; 3</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">a</span>                            <span class="ruby-comment">#=&gt; 2</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">b</span>                            <span class="ruby-comment">#=&gt; NameError</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This method behaves similarly to the following code:</p>

<pre class="ruby"><span class="ruby-identifier">binding</span>.<span class="ruby-identifier">eval</span>(<span class="ruby-node">&quot;#{symbol} = #{obj}&quot;</span>)
</pre>

<p>if <code>obj</code> can be dumped in Ruby code.</p>

                              <div class="method-source-code" id="local_variable_set-source">
            <pre>static VALUE
bind_local_variable_set(VALUE bindval, VALUE sym, VALUE val)
{
    ID lid = check_local_id(bindval, &amp;sym);
    rb_binding_t *bind;
    const VALUE *ptr;
    const rb_env_t *env;

    if (!lid) lid = rb_intern_str(sym);

    GetBindingPtr(bindval, bind);
    env = VM_ENV_ENVVAL_PTR(vm_block_ep(&amp;bind-&gt;block));
    if ((ptr = get_local_variable_ptr(&amp;env, lid)) == NULL) {
        /* not found. create new env */
        ptr = rb_binding_add_dynavars(bindval, bind, 1, &amp;lid);
        env = VM_ENV_ENVVAL_PTR(vm_block_ep(&amp;bind-&gt;block));
    }

#if YJIT_STATS
    rb_yjit_collect_binding_set();
#endif

    RB_OBJ_WRITE(env, ptr, val);

    return val;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-local_variables" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          local_variables &rarr; Array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the names of the binding’s local variables as symbols.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
  <span class="ruby-identifier">a</span> = <span class="ruby-value">1</span>
  <span class="ruby-value">2</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">binding</span>.<span class="ruby-identifier">local_variables</span> <span class="ruby-comment">#=&gt; [:a, :n]</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This method is the short version of the following code:</p>

<pre class="ruby"><span class="ruby-identifier">binding</span>.<span class="ruby-identifier">eval</span>(<span class="ruby-string">&quot;local_variables&quot;</span>)
</pre>

                              <div class="method-source-code" id="local_variables-source">
            <pre>static VALUE
bind_local_variables(VALUE bindval)
{
    const rb_binding_t *bind;
    const rb_env_t *env;

    GetBindingPtr(bindval, bind);
    env = VM_ENV_ENVVAL_PTR(vm_block_ep(&amp;bind-&gt;block));
    return rb_vm_env_local_variables(env);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-receiver" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          receiver    &rarr; object
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the bound receiver of the binding object.</p>

                              <div class="method-source-code" id="receiver-source">
            <pre>static VALUE
bind_receiver(VALUE bindval)
{
    const rb_binding_t *bind;
    GetBindingPtr(bindval, bind);
    return vm_block_self(&amp;bind-&gt;block);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-source_location" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          source_location  &rarr; [String, Integer]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the Ruby source filename and line number of the binding object.</p>

                              <div class="method-source-code" id="source_location-source">
            <pre>static VALUE
bind_location(VALUE bindval)
{
    VALUE loc[2];
    const rb_binding_t *bind;
    GetBindingPtr(bindval, bind);
    loc[0] = pathobj_path(bind-&gt;pathobj);
    loc[1] = INT2FIX(bind-&gt;first_lineno);

    return rb_ary_new4(2, loc);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

